package com.hl.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hl.mapper.ShoppingCartMapper;
import com.hl.domain.ShoppingCart;
import com.hl.service.IShoppingCartService;
import java.util.ArrayList;

/**
 * 用户购物车Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@Service
public class ShoppingCartServiceImpl implements IShoppingCartService 
{
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    /**
     * 查询用户购物车
     * 
     * @param id 用户购物车主键
     * @return 用户购物车
     */
    @Override
    public ShoppingCart selectShoppingCartById(Integer id)
    {
        return shoppingCartMapper.selectShoppingCartById(id);
    }

    /**
     * 查询用户购物车列表
     * 
     * @param shoppingCart 用户购物车
     * @return 用户购物车
     */
    @Override
    public List<ShoppingCart> selectShoppingCartList(ShoppingCart shoppingCart)
    {
        // 安全验证：确保memberId不为空
        if (shoppingCart == null || shoppingCart.getMemberId() == null) {
            return new ArrayList<>();
        }
        return shoppingCartMapper.selectShoppingCartList(shoppingCart);
    }

    /**
     * 新增用户购物车
     * 
     * @param shoppingCart 用户购物车
     * @return 结果
     */
    @Override
    public int insertShoppingCart(ShoppingCart shoppingCart)
    {
        return shoppingCartMapper.insertShoppingCart(shoppingCart);
    }

    /**
     * 修改用户购物车
     * 
     * @param shoppingCart 用户购物车
     * @return 结果
     */
    @Override
    public int updateShoppingCart(ShoppingCart shoppingCart)
    {
        return shoppingCartMapper.updateShoppingCart(shoppingCart);
    }

    /**
     * 批量删除用户购物车
     * 
     * @param ids 需要删除的用户购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingCartByIds(Integer[] ids)
    {
        return shoppingCartMapper.deleteShoppingCartByIds(ids);
    }

    /**
     * 删除用户购物车信息
     * 
     * @param id 用户购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingCartById(Integer id)
    {
        return shoppingCartMapper.deleteShoppingCartById(id);
    }
}
